package com.itheima.service;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Student;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class StudentServiceText {

    @Autowired
    private StudentService studentService;
    @Test
    public void testSave() {
        Student student = new Student();
        student.setName("雪琳");
        student.setAge(20);
        student.setBirthday(new Date());
        studentService.save(student);
    }

    @Test
    public void testUpdate() {
        Student student = new Student();
        student.setId(2);
        student.setName("宋雪琳");
        student.setAge(20);
        student.setBirthday(new Date());
        studentService.update(student);
    }

    @Test
    public void testDelete() {
        studentService.delete(2);
    }

    @Test
    public void testFindById() {
        System.out.println(studentService.findById(1));
    }

    @Test
    public void testGetAll() {
        PageInfo<Student> all = studentService.findAll(1, 3);
        System.out.println(all.getList());
        System.out.println(all.getList().get(0));
        System.out.println(all.getList().get(2));
    }

}
